#include "ElectionFactory.h"
#include "NationalElection.h"
#include "StateElection.h"
#include "LocalElection.h"

#include <iostream>
#include <sstream>

using namespace std;

Election* ElectionFactory::GetElection(string& data)
{
	stringstream ss(data);
	Election* election;
	string level;
	
	string name;
	int num_candidate;
	vector<string> candidates;

	ss >> level;
	if( level == "national" ) 
	{
		ss >> name >> num_candidate;
		for(int i=0;i<num_candidate;++i) {
			string candidate;
			ss >> candidate;
			candidates.push_back(candidate);
		}
		election = new NationalElection( name, candidates ) ;
	}
	else if( level == "state" )
	{
		string state;
		ss >> state;

		ss >> name >> num_candidate;
		for(int i=0;i<num_candidate;++i) {
			string candidate;
			ss >> candidate;
			candidates.push_back(candidate);
		}
		election = new StateElection( name, candidates, state ) ;
	}
	else
	{
		// local
		string state, local;
		ss >> state >> local;
		
		ss >> name >> num_candidate;
		for(int i=0;i<num_candidate;++i) {
			string candidate;
			ss >> candidate;
			candidates.push_back(candidate);
		}
		election = new LocalElection( name, candidates, state, local ) ;

	}

	return election;
}